﻿using Application.MainModule.RetailRateManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.RetailRates;
using Domain.MainModule.Entities;
using System.Collections.Generic;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for RetailRateManagementServiceTest and is intended
    ///to contain all RetailRateManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RetailRateManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddRetailRate
        ///</summary>
        [TestMethod()]
        public void AddRetailRate_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            Guid retailRateId = Guid.NewGuid();
            RetailRate retailRate = new RetailRate()
            {
                RetailRateId = retailRateId,                
            };

            //Act
            target.AddRetailRate(retailRate);
            RetailRate result = target.FindRetailRateById(retailRateId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(retailRateId, result.RetailRateId); 
        }

        /// <summary>
        ///A test for ChangeRetailRate
        ///</summary>
        [TestMethod()]
        public void ChangeRetailRate_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            Guid retailRateId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBBB");
 
            //Act
            RetailRate retailRate = target.FindRetailRateById(retailRateId);
            retailRate.UpdateDate = new DateTime(2010, 12, 25);
            target.ChangeRetailRate(retailRate);
            RetailRate result = target.FindRetailRateById(retailRateId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual(new DateTime(1980, 5, 10), result.UpdateDate);
        }

		/// <summary>
        ///A test for FindRetailRateById
        ///</summary>
        [TestMethod()]
        public void FindRetailRateById_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            Guid retailRateId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBBB");

            //Act 
            RetailRate retailRate = target.FindRetailRateById(retailRateId);

            //Assert
            Assert.IsNotNull(retailRate);
            Assert.AreEqual(retailRateId, retailRate.RetailRateId);
        }
		
        /// <summary>
        ///A test for FindRetailRateByBranchId
        ///</summary>
        [TestMethod()]
        public void FindRetailRateByBranchId_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            Guid branchId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBB0");

            //Act
            List<RetailRate> actual;
            actual = target.FindRetailRateByBranchId(branchId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(branchId, actual[0].BranchId);
        }
		
		/// <summary>
        ///A test for FindRetailRateByRateId
        ///</summary>
        [TestMethod()]
        public void FindRetailRateByRateId_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            Guid rateId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBB19");

            //Act
            List<RetailRate> actual;
            actual = target.FindRetailRateByRateId(rateId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(rateId, actual[0].RateId);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveRetailRate_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();

            //Act
            target.RemoveRetailRate(null);
        }

        /// <summary>
        ///A test for RemoveRetailRate
        ///</summary>
        [TestMethod()]
        public void RemoveRetailRate_Invoke_Test()
        {
            //Arrange
            IRetailRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRetailRateManagementService>();
            RetailRate retailRate = null;

            //Act
            retailRate = target.FindRetailRateById(Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBBB"));
            target.RemoveRetailRate(retailRate);

            //Assert
            RetailRate result = target.FindRetailRateById(Guid.Parse("ABCDF000-1234-5678-9000-1234567890AB"));
            Assert.IsNull(result);
            retailRate = new RetailRate()
            {
                RetailRateId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBBB"),
                UpdateDate = new DateTime(1980, 5, 10),
                BranchId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBBB9"),
                RateId = Guid.Parse("ABCDF456-1234-5678-90AB-AAAACCBBBB19")
            };

            target.AddRetailRate(retailRate);
        }
    }
}
